import React, { Component } from 'react'
import { connect } from 'react-redux'
import action from './store/actions/home'
class Home extends Component {
  componentDidMount () {
    this.props.getBannerList()
    this.props.getProList()
  }
  render() {
    const { bannerList, proList } = this.props
    return (
      <div>
        {
          bannerList && bannerList.map(item => (
            <img key = { item.bannerid } src={ item.img } alt={ item.alt }/>
          ))
        }
        {
          proList && proList.map(item => (
            <div key = { item.proid }>{ item.proname }</div>
          ))
        }
      </div>
    )
  }
}

export default connect((state) => {
  return {
    bannerList: state.home.bannerList,
    proList: state.home.proList
  }
}, (dispatch) => {
  return {
    getBannerList () {
      dispatch(action.getBannerListAction)
    },
    getProList () {
      dispatch(action.getProListAction({ limitNum: 4 }))
    }
  }
})(Home)
